package com.chenyun.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.bean.BeanUtil;
import com.chenyun.common.annotation.Page;
import com.chenyun.system.model.SysOperLog;
import com.chenyun.system.service.ISysOperLogService;
import com.chenyun.boot.web.controller.BaseController;
import com.chenyun.common.vo.AjaxResult;
import com.chenyun.common.vo.OperLog;
import com.chenyun.common.vo.PageResult;
import com.chenyun.satoken.starter.annotation.SaCheckAdmin;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 操作日志记录
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/operlog")
@Api(tags = "操作日志记录-admin")
@SaCheckAdmin
public class SysOperlogController extends BaseController<ISysOperLogService,SysOperLog>
{
    @Autowired
    private ISysOperLogService operLogService;


    @ApiOperation("列表")
    @PostMapping("/list")
    @SaCheckPermission("system:operlog:list")
    public PageResult list(@RequestBody SysOperLog operLog)
    {
        List<SysOperLog> list = operLogService.selectOperLogList(operLog);
        return getDataTable(list);
    }
    @ApiOperation("删除")
    @PostMapping("del")
    @SaCheckPermission("system:operlog:del")
    public AjaxResult remove(@RequestBody Long[] operIds)
    {
        return toAjax(operLogService.deleteOperLogByIds(operIds));
    }

    @ApiOperation("清空所有操作日志")
    @PostMapping("/clean")
    @SaCheckPermission("system:operlog:clean")
    public AjaxResult clean()
    {
        operLogService.cleanOperLog();
        return AjaxResult.SUCCESS();
    }
    @PostMapping
    @SaCheckPermission("system:operlog:addop")
    public AjaxResult add(@RequestBody SysOperLog operLog)
    {
        return toAjax(operLogService.insertOperlog(operLog));
    }

    @PostMapping("add")
    @SaCheckPermission("system:operlog:add")
    public AjaxResult addLog(@RequestBody OperLog log)
    {
        SysOperLog log1=new SysOperLog();
        BeanUtil.copyProperties(log,log1);
        return toAjax(operLogService.insertOperlog(log1));
    }
}
